<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/layui-src@2.6.4/dist/css/layui.css">
    <script src="//cdn.jsdelivr.net/npm/layui-src@2.6.4/dist/layui.js"></script>
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="redel" lay-event="del">删除</a>
</script>



<script th:inline="none">
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'/report/list'
            ,toolbar: '#toolbarDemo'
            ,title: '用户数据表'
            ,totalRow: true
            ,response:{
                countName:'count',
                dataName:'datas'
            }
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', width:80, title: 'ID', sort: true}
                ,{field:'createTime', width:280, title: '创建时间',templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field:'userId', width:80, title: '用户ID', sort: true}
                ,{field:'remark', width:80, title: '评论', sort: true}
                ,{field:'temperature', width:120, title: '体温状况', sort: true}
                ,{field:'travel', width:80, title: '旅行', sort: true}
                ,{field:'travelDescription', width:200, title: '旅行情况', sort: true}
                ,{field:'physicalCondition', title: '身体状况', sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(test)', function(obj){
            $ = layui.jquery;
            var data=obj.data;
            var id =data.id;

            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        url: "/report/delete",    //这个是后台的路由地址
                        type: "POST",
                        data: {"id":id},
                        dataType: "json",
                        success: function(data){
                            layer.msg('已删除!', {icon: 1,time:1},function(data){
                                window.parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        }
                    })
                });
            }else if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    title: '信息编辑',
                    skin:'layui-layer-demo',
                    closeBtn:1,
                    anim:2,
                    shadeClose:true,
                    area: ['1000px', '500px'], //宽高
                    content:'/report/dictById?id='+id,
                })
            }

        });
    });

</script>

</body>
</html>